package 方法的引用;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;

public class 引用成员方法 {
    public static void main(String[] args) {
        //1.创建集合
        ArrayList<String> strList=new ArrayList<>();
        Collections.addAll(strList,"张无忌","周芷若","赵敏","张强","张三丰");
        //需求只要以"张"开头,而且名字要3个字
        //旧方法
        strList.stream().filter(s -> s.startsWith("张")).filter(s -> s.length()==3)
                .forEach(System.out::println);

        //匿名内部类
//        strList.stream().filter(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                return s.startsWith("张")&&s.length()==3;
//            }
//        }).forEach(System.out::println);

        //方法引用
        strList.stream().filter(StringOpertion::stringJudge).forEach(System.out::println);

        //本类
        //静态方法中没有this
        strList.stream().filter(引用成员方法::stringJudge);

    }

    public static boolean stringJudge(String s) {
        return s.startsWith("张") && s.length() == 3;
    }
}
